package com.github.yealove.configgen.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NacosMapper {

    @Select("select host from cg_nacos_server")
    List<String> getNacosServers();

    @Insert({
            "<script>",
            "insert into ",
            "cg_nacos_server(host)",
            "values",
            "<foreach collection='servers' item='server' separator=','>",
            "(#{server})",
            "</foreach>",
            "</script>"
    })
    void saveNacosServers(List<String> servers);

    @Delete("delete from cg_nacos_server")
    void deleteAll();
}
